﻿// Java Document

var MinMilli = 1000 * 60
var HrMilli = MinMilli * 60
var DyMilli = HrMilli * 24
	
function L_calendar(){}
L_calendar.prototype={
    _VersionInfo:"Version:1.0&#13;作者: lingye",
    Moveable:true,
    NewName:"",
    insertId:"",
    ClickObject:null,
    InputObject:null,
    todayvalid:true,
    startDate:"",
    endDate:"",
    InputDate:null,
    IsOpen:false,
    MouseX:0,
    MouseY:0,
    isClickPoveDate:false,
    GetDateLayer:function(){
        if(window.parent){
            return window.parent.L_DateLayer;
        }
        else{return window.L_DateLayer;}
        },
    L_TheYear:new Date().getFullYear(), //定义年的变量的初始值
	L_TheYearT:new Date().getFullYear(), //定义年的变量的初始值
    L_TheMonth:new Date().getMonth()+1,//定义月的变量的初始值
	L_TheMonthT:new Date().getMonth()+1,//定义月的变量的初始值
    L_WDay:new Array(39),//定义写日期的数组
	L_WDayT:new Array(39),//定义写日期的数组
    MonHead:new Array(31,28,31,30,31,30,31,31,30,31,30,31),               //定义阳历中每个月的最大天数
    GetY:function(){
        var obj;
        if (arguments.length > 0){
            obj==arguments[0];
            }
        else{
            obj=this.ClickObject;
            }
        if(obj!=null){
            var y = obj.offsetTop;
            while (obj = obj.offsetParent) y += obj.offsetTop;
            return y;}
        else{return 0;}
        },
    GetX:function(){
        var obj;
        if (arguments.length > 0){
            obj==arguments[0];
            
            }
        else{
            obj=this.ClickObject;
            }
        if(obj!=null){
            var y = obj.offsetLeft;
            while (obj = obj.offsetParent) y += obj.offsetLeft;
            return y;}
        else{return 0;}
        },
    CreateHTML:function(){
        var htmlstr="";
        htmlstr+="<div id=maincalendar><div id=\"L_calendar\">\r\n";
        htmlstr+="<span id=\"SelectYearLayer\" style=\"z-index: 9999;position: absolute;top: 3; left: 19;display: none\"></span>\r\n";
        htmlstr+="<span id=\"SelectMonthLayer\" style=\"z-index: 9999;position: absolute;top: 3; left: 78;display: none\"></span>\r\n";
        htmlstr+="<div id=\"L_calendar-year-month\"><div id=\"L_calendar-PrevM\" onclick=\"parent."+this.NewName+".PrevM()\" title=\"前一月\"><b>&lt;</b></div><div id=\"L_calendar-year\"></div><div id=\"L_calendar-month\"></div><div id=\"L_calendar-NextM\" onclick=\"parent."+this.NewName+".NextM()\" title=\"后一月\"><b>&gt;</b></div></div>\r\n";
        htmlstr+="<div id=\"L_calendar-week\"><ul onmouseup=\"StopMove()\"><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul></div>\r\n";
        htmlstr+="<div id=\"L_calendar-day\">\r\n";
        htmlstr+="<ul>\r\n";
        for(var i=0;i<this.L_WDay.length;i++){
            htmlstr+="<li id=\"L_calendar-day_"+i+"\" style=\"background-color:#FFFFFF\" onmouseover=\"this.style.background='#c8e3fc'\" onmouseout=\"this.style.background='#FFFFFF'\"></li>\r\n";
            }
        htmlstr+="</ul>\r\n";
        htmlstr+="<span id=\"L_calendar-today\" onclick=\"parent."+this.NewName+".Today()\"><b>Today</b></span>\r\n";
        htmlstr+="</div>\r\n";
        //htmlstr+="<div id=\"L_calendar-control\"></div>\r\n";
        htmlstr+="</div>\r\n";
		htmlstr+="<div id=\"L_calendarT\">\r\n";
        htmlstr+="<span id=\"SelectYearLayerT\" style=\"z-index: 9999;position: absolute;top: 3; left: 177;display: none\"></span>\r\n";
        htmlstr+="<span id=\"SelectMonthLayerT\" style=\"z-index: 9999;position: absolute;top: 3; left: 236;display: none\"></span>\r\n";
        htmlstr+="<div id=\"L_calendar-year-monthT\"><div id=\"L_calendar-PrevMT\" onclick=\"parent."+this.NewName+".PrevM()\" title=\"前一月\"><b>&lt;</b></div><div id=\"L_calendar-yearT\" ></div><div id=\"L_calendar-monthT\" ></div><div id=\"L_calendar-NextMT\" onclick=\"parent."+this.NewName+".NextM()\" title=\"后一月\"><b>&gt;</b></div></div>\r\n";
        htmlstr+="<div id=\"L_calendar-weekT\"><ul onmouseup=\"StopMove()\"><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul></div>\r\n";
        htmlstr+="<div id=\"L_calendar-dayT\">\r\n";
        htmlstr+="<ul>\r\n";
        for(var i=0;i<this.L_WDayT.length;i++){
            htmlstr+="<li id=\"L_calendar-dayT_"+i+"\" style=\"background-color:#FFFFFF\" onmouseover=\"this.style.background='#c8e3fc'\" onmouseout=\"this.style.background='#FFFFFF'\"></li>\r\n";
            }
        htmlstr+="</ul>\r\n";
        htmlstr+="</div>\r\n";
        //htmlstr+="<div id=\"L_calendar-control\"></div>\r\n";
        htmlstr+="</div></div>\r\n";
        htmlstr+="<scr" + "ipt type=\"text/javas" + "cript\">\r\n";
        htmlstr+="var MouseX,MouseY;";
        htmlstr+="var Moveable="+this.Moveable+";\r\n";
        htmlstr+="var MoveaStart=false;\r\n";
        htmlstr+="document.onmousemove=function(e)\r\n";
        htmlstr+="{\r\n";
        htmlstr+="var DateLayer=parent.document.getElementById(\"L_DateLayer\");\r\n";
        htmlstr+="    e = window.event || e;\r\n";
        htmlstr+="var DateLayerLeft=DateLayer.style.posLeft || parseInt(DateLayer.style.left.replace(\"px\",\"\"));\r\n";
        htmlstr+="var DateLayerTop=DateLayer.style.posTop || parseInt(DateLayer.style.top.replace(\"px\",\"\"));\r\n";
        htmlstr+="if(MoveaStart){DateLayer.style.left=(DateLayerLeft+e.clientX-MouseX)+\"px\";DateLayer.style.top=(DateLayerTop+e.clientY-MouseY)+\"px\"}\r\n";
        htmlstr+=";\r\n";
        htmlstr+="}\r\n";
        
        htmlstr+="document.getElementById(\"L_calendar-week\").onmousedown=function(e){\r\n";
        htmlstr+="if(Moveable){MoveaStart=true;}\r\n";
        htmlstr+="    e = window.event || e;\r\n";
        htmlstr+=" MouseX = e.clientX;\r\n";
        htmlstr+=" MouseY = e.clientY;\r\n";
        htmlstr+="    }\r\n";
        
        htmlstr+="function StopMove(){\r\n";
        htmlstr+="MoveaStart=false;\r\n";
        htmlstr+="    }\r\n";
        htmlstr+="</scr"+"ipt>\r\n";
        var stylestr="";
        stylestr+="<style type=\"text/css\">";
        stylestr+="body{background:#fff;font-size:12px;margin:0px;padding:0px;text-align:left}\r\n";
		stylestr+="#maincalendar{width:320px;padding:1px;height:180px;z-index:9998;text-align:center}\r\n";

        stylestr+="#L_calendar{border:1px solid #2F7495;width:158px;padding:1px;height:180px;z-index:9998;text-align:center;float:left}\r\n";
        stylestr+="#L_calendar-year-month{height:23px;line-height:23px;z-index:9998;background-color: #c8e3fc;}\r\n";
        stylestr+="#L_calendar-year{line-height:23px;width:60px;float:left;z-index:9998;position: absolute;top: 3; left: 35;cursor:default}\r\n";
        stylestr+="#L_calendar-month{line-height:23px;width:48px;float:left;z-index:9998;position: absolute;top: 3; left: 76;cursor:default}\r\n";
        stylestr+="#L_calendar-PrevM{position: absolute;top: 3; left: 5;cursor:pointer}";
        stylestr+="#L_calendar-NextM{position: absolute;top: 3; left: 145;cursor:pointer}";
        stylestr+="#L_calendar-week{height:23px;line-height:23px;z-index:9998;background-color: #e7f1fd;color:#656565}\r\n";
        stylestr+="#L_calendar-day{height:136px;z-index:9998;}\r\n";
        stylestr+="#L_calendar-week ul{cursor:move;list-style:none;margin:0px;padding:0px;}\r\n";
        stylestr+="#L_calendar-week li{width:20px;height:20px;float:left;;margin:1px;padding:0px;text-align:center;}\r\n";
        stylestr+="#L_calendar-day ul{list-style:none;margin:0px;padding:0px;}\r\n";
        stylestr+="#L_calendar-day li{cursor:pointer;width:20px;height:20px;float:left;;margin:1px;padding:0px;}\r\n";
        stylestr+="#L_calendar-control{height:25px;z-index:9998;}\r\n";
        stylestr+="#L_calendar-today{cursor:pointer;float:left;width:63px;height:20px;line-height:20px;margin:1px;text-align:center;background:red;display:none}";

        stylestr+="#L_calendarT{border:1px solid #2F7495;width:158px;padding:0px;height:180px;z-index:9998;text-align:center;float:left}\r\n";
        stylestr+="#L_calendar-year-monthT{height:23px;line-height:23px;z-index:9998;background-color: #c8e3fc;margin:1px;}\r\n";
        stylestr+="#L_calendar-yearT{line-height:23px;width:60px;float:left;z-index:9998;position: absolute;top: 3; left: 191;cursor:default}\r\n";
        stylestr+="#L_calendar-monthT{line-height:23px;width:48px;float:left;z-index:9998;position: absolute;top: 3; left: 235;cursor:default}\r\n";
        stylestr+="#L_calendar-PrevMT{position: absolute;top: 3; left: 163;cursor:pointer}";
        stylestr+="#L_calendar-NextMT{position: absolute;top: 3; left: 303;cursor:pointer}";
        stylestr+="#L_calendar-weekT{height:23px;line-height:23px;z-index:9998;background-color: #e7f1fd;color:#656565}\r\n";
        stylestr+="#L_calendar-dayT{height:136px;z-index:9998;}\r\n";
        stylestr+="#L_calendar-weekT ul{cursor:move;list-style:none;margin:0px;padding:0px;}\r\n";
        stylestr+="#L_calendar-weekT li{width:20px;height:20px;float:left;;margin:1px;padding:0px;text-align:center;}\r\n";
        stylestr+="#L_calendar-dayT ul{list-style:none;margin:0px;padding:0px;}\r\n";
        stylestr+="#L_calendar-dayT li{cursor:pointer;width:20px;height:20px;float:left;;margin:1px;padding:0px;}\r\n";
        stylestr+="#L_calendar-controlT{height:25px;z-index:9998;}\r\n";
        stylestr+="#L_calendar-todayT{cursor:pointer;float:left;width:63px;height:20px;line-height:20px;margin:1px;text-align:center;background:red}";
        stylestr+="</style>";
        var TempLateContent="<html>\r\n";
        TempLateContent+="<head>\r\n";
        TempLateContent+="<title></title>\r\n";
        TempLateContent+=stylestr;
        TempLateContent+="</head>\r\n";
        TempLateContent+="<body>\r\n";
        TempLateContent+=htmlstr;
        TempLateContent+="</body>\r\n";
        TempLateContent+="</html>\r\n";
        this.GetDateLayer().document.writeln(TempLateContent);
        this.GetDateLayer().document.close();
        },
    InsertHTML:function(id,htmlstr){
        var L_DateLayer=this.GetDateLayer();
        if(L_DateLayer){L_DateLayer.document.getElementById(id).innerHTML=htmlstr;}
        },
    WriteHead:function (yy,mm) //往 head 中写入当前的年与月
    {
        this.InsertHTML("L_calendar-year",yy + " 年");
        this.InsertHTML("L_calendar-month",mm + " 月");
    },
	WriteHeadT:function (yy,mm) //往 head 中写入当前的年与月
    {
        this.InsertHTML("L_calendar-yearT",yy + " 年");
        this.InsertHTML("L_calendar-monthT",mm + " 月");
    },
    IsPinYear:function(year)            //判断是否闰平年
    {
        if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
    },
    GetMonthCount:function(year,month) //闰年二月为29天
    {
        var c=this.MonHead[month-1];if((month==2)&&this.IsPinYear(year)) c++;return c;
    },
    GetDOW:function(day,month,year)     //求某天的星期几
    {
        var dt=new Date(year,month-1,day).getDay()/7; return dt;
    },
    GetText:function(obj){
        if(obj.innerText){return obj.innerText}
        else{return obj.textContent}
        },
    PrevM:function() //往前翻月份
    {
        if(this.L_TheMonth>1){this.L_TheMonth--}else{this.L_TheYear--;this.L_TheMonth=12;}
        this.SetDay(this.L_TheYear,this.L_TheMonth);
    },
    NextM:function() //往后翻月份
    {
        if(this.L_TheMonth==12){this.L_TheYear++;this.L_TheMonth=1}else{this.L_TheMonth++}
        this.SetDay(this.L_TheYear,this.L_TheMonth);
    },
    Today:function() //Today Button
    {
        var today;
        this.L_TheYear = new Date().getFullYear();
        this.L_TheMonth = new Date().getMonth()+1;
        today=new Date().getDate();
        if(this.InputObject){
        this.InputObject.value=this.L_TheYear + "-" + this.L_TheMonth + "-" + today;
        }
        this.CloseLayer();
    },
    	
    SetDay:function (yy,mm)   //主要的写程序**********
    {
        this.WriteHead(yy,mm);
        //设置当前年月的公共变量为传入值
        this.L_TheYear=yy;
        this.L_TheMonth=mm;
		
        var b=new Date(yy,mm-1,1);
		var a=new Date();
		
        for (var i = 0; i < this.L_WDay.length; i++){this.L_WDay[i]=""}; //将显示框的内容全部清空
        	
        var day1 = 1,day2=1;
        var firstday = new Date(yy,mm-1,1); //某月第一天
        
        var lastday = new Date(yy,mm,1);	
        lastday.setTime(lastday.getTime()-DyMilli);//某月的最后一天
        
     	var loopDate=new Date(yy,mm-1,1);
     	loopDate.setTime(loopDate.getTime()-(firstday.getDay())*DyMilli);
        for(i=0;i<this.L_WDay.length;i++){
        	var date=new Date();
        	date.setTime(loopDate.getTime());
			this.L_WDay[i]=date;
			loopDate.setTime(loopDate.getTime()+DyMilli);
        }
        
        //写第一个月
        var today=new Date();
        var tommorrow = new Date();
        tommorrow.setTime(today.getTime()+DyMilli);
        var startDayCount="";
        var endDayCount="";
                
        for (i = 0; i < 39; i++)
        {
            var da=this.GetDateLayer().document.getElementById("L_calendar-day_"+i+"");
            var month,day;
            var thisMonth=new Date().getMonth();
            if (this.L_WDay[i]!="")
            { 
            	if(this.L_WDay[i]<firstday){
            		//面板要显示的月份的上一个月
                    da.innerHTML="<font style=\"color:gray;display:none;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDay[i].getDay();
					if(document.all){
                         da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
            	}else if(this.L_WDay[i].getFullYear()==today.getFullYear() 
            	&& (this.L_WDay[i].getMonth()+1)==(today.getMonth()+1)
            	&& this.L_WDay[i].getDate()==today.getDate()
            	&& this.L_WDay[i] > firstday
            	&& this.L_WDay[i] < lastday){
            			//对今天的情况进行处理
						da.innerHTML="<font style=\"color:#FF0000;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>"; 
						if(document.all){
	                         da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                    }else{
	                         da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                    }
            	}else if(this.L_WDay[i]>today && this.L_WDay[i]<=lastday){
            				//面板要显示的月份
					    	da.innerHTML="<font style=\"color:#21407D;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>"; 
						    if(document.all){
	                            da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                        }
	                        else{
	                            da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                        }
            	}else if(this.L_WDay[i]>lastday){
            	    //面板要显示的月份的下一个月
                    da.innerHTML="<font style=\"color:gray;display:none;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDay[i].getDay();
					if(document.all){
                         da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
            	}else if(this.L_WDay[i].getFullYear()==today.getFullYear() 
            	&& (this.L_WDay[i].getMonth()+1)==(today.getMonth()+1)
            	&& this.L_WDay[i].getDate()==today.getDate()){
					da.innerHTML="<font style=\"color:#FF0000;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>"; 
						if(document.all){
	                         da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                    }else{
	                         da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                    }
				}else{
            		//面板要显示的月份，但是他在今天之前
                    da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDay[i].getDay();
                    if(this.isClickPoveDate){
                        if(document.all){
	                        da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
                        }
                        else{
                            da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
                        }
                    }else{
					    if(document.all){
                             da.onclick="";
                        }
                        else{
                            da.setAttribute("onclick","");
                        }
                    }
            	}
				
                da.title=this.L_WDay[i].getMonth()+1+" 月"+this.L_WDay[i].getDate()+" 日";
                
                //更改今天的日期背景色
                if(this.todayvalid==true){	
                }else {
                	da.style.background=(this.L_WDay[i]==tommorrow)? "#c8e3fc":"#FFFFFF";
                	//如果今天默认不可用
                	if(this.L_WDay[i].getFullYear()==today.getFullYear() 
                	&& this.L_WDay[i].getMonth()==today.getMonth() 
                	&& this.L_WDay[i].getDate()==today.getDate()
	            	&& this.L_WDay[i] > firstday
	            	&& this.L_WDay[i] < lastday){
                		da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
                		//那么今天将不可点击
						    if(document.all){
                                da.onclick="";
                            }
                            else{
                                da.setAttribute("onclick","");
                            }
                	}
                }
                
                if(this.startDate!="" && this.L_WDay[i]<this.startDate && this.L_WDay[i]>=firstday && this.L_WDay[i]<=lastday){
                	//如果startDate有效，且L_WDayT[i]在这个日期之前，则设置为无效。
                	da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
					if(document.all){
                        da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
                }
                
                if(this.endDate!="" && this.L_WDay[i]>this.endDate && this.L_WDay[i]>=firstday && this.L_WDay[i]<=lastday){
                	//如果endDate有效，且日期在endDate之后，则设置为无效
                	da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDay[i].getDate() + "</font>";
					if(document.all){
                        da.onclick="";
                    }
                    else{
                        a.setAttribute("onclick","");
                    }      
                }
                
                if(this.InputDate!=null){
                    if(yy==this.InputDate.getFullYear() && month== this.InputDate.getMonth() + 1 && day==this.InputDate.getDate()){
                    }
                }
              }
        }
			
		if (Number(mm)==12){
		    mm=1; 
		    yy=Number(yy)+1;
		}
		else{
		    mm=Number(mm)+1;
		}
		this.WriteHeadT(yy,mm);
		this.L_TheYearT=yy;
		this.L_TheMonthT=mm;
		
		//第二个月
		//alert(mm);
		for (var i = 0; i < 39; i++){this.L_WDayT[i]=""}; //将显示框的内容全部清空
        firstday = new Date(yy,mm-1,1);
        lastday = new Date(yy,mm,1);	
        lastday.setTime(lastday.getTime()-DyMilli);//某月的最后一天
        
        loopDate=new Date(yy,mm-1,1);
     	loopDate.setTime(loopDate.getTime()-(firstday.getDay())*DyMilli);
        for(i=0;i<this.L_WDayT.length;i++){
        	var date=new Date();
        	date.setTime(loopDate.getTime());
			this.L_WDayT[i]=date;
			loopDate.setTime(loopDate.getTime()+DyMilli);
        }
        
        for (i = 0; i < 39; i++)
        {
            var da=this.GetDateLayer().document.getElementById("L_calendar-dayT_"+i+"");
            var month,day;
            if (this.L_WDayT[i]!="")
            { 
            	if(this.L_WDayT[i]<firstday){
            		//上个月
                    da.innerHTML="<font style=\"color:gray;display:none;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDayT[i].getDay();
					if(document.all){
                         da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
            	}else if(this.L_WDayT[i].getFullYear()==today.getFullYear() 
            	&& this.L_WDayT[i].getMonth()==today.getMonth() 
            	&& this.L_WDayT[i].getDate()==today.getDate() 
            	&& this.L_WDayT[i] > firstday
            	&& this.L_WDayT[i] < lastday
            	){
            			//对今天的情况进行处理
						da.innerHTML="<font style=\"color:#21407D;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>"; 
						if(document.all){
	                         da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDayT[i].getFullYear()+","+this.L_WDayT[i].getMonth()+","+this.L_WDayT[i].getDate()+",'F')");
	                    }else{
	                         da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDayT[i].getFullYear()+","+this.L_WDayT[i].getMonth()+","+this.L_WDayT[i].getDate()+",'F')");
	                    }
            	}else if(this.L_WDayT[i]>today && this.L_WDayT[i]<=lastday){
            				//本月今天之后
					    	da.innerHTML="<font style=\"color:#21407D;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>"; 
						    if(document.all){
	                            da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDayT[i].getFullYear()+","+this.L_WDayT[i].getMonth()+","+this.L_WDayT[i].getDate()+",'F')");
	                        }
	                        else{
	                            da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDayT[i].getFullYear()+","+this.L_WDayT[i].getMonth()+","+this.L_WDayT[i].getDate()+",'F')");
	                        }
            	}else if(this.L_WDayT[i]>lastday){
            		//下个月
                    da.innerHTML="<font style=\"color:gray;display:none;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDayT[i].getDay();
					if(document.all){
                         da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
            	}else {
            		//本月 今天之前的日期
                    da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
                    month=(mm==1?12:mm-1);
                    day=this.L_WDayT[i].getDay();
					if(this.isClickPoveDate){
                        if(document.all){
	                            da.onclick=Function("parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                        }
	                        else{
	                            da.setAttribute("onclick","parent."+this.NewName+".DayClick("+this.L_WDay[i].getFullYear()+","+this.L_WDay[i].getMonth()+","+this.L_WDay[i].getDate()+",'F')");
	                        }
                    }else{
					    if(document.all){
                             da.onclick="";
                        }
                        else{
                            da.setAttribute("onclick","");
                        }
                    }
            	}
                da.title=this.L_WDayT[i].getMonth()+1+" 月"+this.L_WDayT[i].getDate()+" 日";
                
                //更改今天的日期背景色
                if(this.todayvalid==true){	
                }else {
                	//如果今天默认不可用
                	if(this.L_WDayT[i].getFullYear()==today.getFullYear() 
                	&& this.L_WDayT[i].getMonth()==today.getMonth() 
                	&& this.L_WDayT[i].getDate()==today.getDate()
	            	&& this.L_WDayT[i] > firstday
	            	&& this.L_WDayT[i] < lastday){
                		da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
                		//那么今天将不可点击
						    if(document.all){
                                da.onclick="";
                            }
                            else{
                                da.setAttribute("onclick","");
                            }
                            //                            
                            da.style.color="#ccc";
                		//更改字体颜色
                	}
                }
                
                if(this.startDate!="" && this.L_WDayT[i]<this.startDate && this.L_WDayT[i]>=firstday && this.L_WDayT[i]<=lastday){
                	da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
					if(document.all){
                        da.onclick="";
                    }
                    else{
                        da.setAttribute("onclick","");
                    }
                }
                
                if(this.endDate!="" && this.L_WDayT[i]>this.endDate && this.L_WDayT[i]>=firstday && this.L_WDayT[i]<=lastday){
                	da.innerHTML="<font style=\"color:gray;font-family: Verdana, Arial, Helvetica, sans-serif\">" + this.L_WDayT[i].getDate() + "</font>";
					if(document.all){
                        da.onclick="";
                    }
                    else{
                        a.setAttribute("onclick","");
                    }
                }
                if(this.InputDate!=null){
                    if(yy==this.InputDate.getFullYear() && month== this.InputDate.getMonth() + 1 && day==this.InputDate.getDate()){
                        //da.style.background="#93C5DD";
                    }
                }
              }
        }
    },
    	
    DayClick:function(year,month,date,flag){
    	month=Number(month)+1;
    	if(month<10){
    		month="0"+month;
    	}
    	
        if (this.ClickObject)
        {
            if (!date)
            {
                return;
            }
            if ( Number(date)< 10)
            {
                date = "0" + date;
            }
            this.InputObject.value= year +"-"+ month +"-"+ date ; //注：在这里你可以输出改成你想要的格式
			this.InputObject.style.color="#000000";
            this.CloseLayer();
        }
        else
        {
            this.CloseLayer();
            alertError("您所要输出的控件对象并不存在！");
        }
    },
   
    SetDate:function(){
        if (arguments.length < 1){alertError("对不起！传入参数太少！");return;}
        this.InputObject=(arguments.length==1) ? arguments[0] : arguments[1];
        
        this.todayvalid=(arguments.length==3)?arguments[2]:true;
        		
        if(this.todayvalid != false && this.todayvalid != true){
        	this.todayvalid=true;        	
        }		
        
		
        var tmpDate=new Date();
        if(arguments.length>3){
            if(arguments[3]!=""){
			    var value=parent.document.getElementById(arguments[3]).value;
    			
			    if(value!=""){
				    tmpDate=new Date(value.substring(0,4),parseInt(value.substring(5,7),10)-1,value.substring(8,10));
			    }else {
				    tmpDate=null;
			    }
			}
        }
        
		//设置startDate
		if(arguments.length>4){
			if(!tmpDate||tmpDate=="NaN"||tmpDate=="Invalid Date"){
			    if(arguments.length==7){
			        alertError(arguments[6]);
			    }else{
				    alertError("请先选择出发日期");
				}
				return ;
			}
			
			this.startDate=new Date();
			this.startDate.setTime(tmpDate.getTime()+parseInt(arguments[4],10)*DyMilli);
		}else {
			this.startDate="";
		}
		
		//设置endDate
		if(arguments.length>5){
			this.endDate=new Date();
			this.endDate.setTime(tmpDate.getTime()+parseInt(arguments[5],10)*DyMilli);
		}else {
			this.endDate="";
		}

		                
        this.ClickObject=arguments[0];
        var reg = /^(\d{4})(\d{2})(\d{2})$/;
        var r = this.InputObject.value.match(reg); 
        if(r!=null){
            r[2]=r[2]-1; 
            var d= new Date(r[1], r[2],r[3]); 
            if(d.getFullYear()==r[1] && d.getMonth()==r[2] && d.getDate()==r[3]){
                this.InputDate=d;        //保存外部传入的日期
            }
            else this.InputDate="";
            this.L_TheYear=r[1];
            this.L_TheMonth=r[2]+1;
            }
        else{
            this.L_TheYear=new Date().getFullYear();
            this.L_TheMonth=new Date().getMonth() + 1
        }
        //2010.07.23
        if(this.startDate!=""){
            this.L_TheYear=this.startDate.getFullYear();
            this.L_TheMonth=this.startDate.getMonth()+1;
        }else {
        }
        this.CreateHTML();
        var top=this.GetY();
        var left=this.GetX();
        var DateLayer=document.getElementById("L_DateLayer");
        DateLayer.style.top=top+this.ClickObject.clientHeight+5+"px";
        DateLayer.style.left=left+"px";
        DateLayer.style.display="block";
        if(document.all){
            this.GetDateLayer().document.getElementById("L_calendar").style.width="160px";
            this.GetDateLayer().document.getElementById("L_calendar").style.height="180px"
            }
        else{
            this.GetDateLayer().document.getElementById("L_calendar").style.width="154px";
            this.GetDateLayer().document.getElementById("L_calendar").style.height="180px"
            //DateLayer.style.width="320px";
            //DateLayer.style.height="200px";
            }
        this.SetDay(this.L_TheYear,this.L_TheMonth);
        },
    CloseLayer:function(){
        try{
            var DateLayer=document.getElementById("L_DateLayer");
            if((DateLayer.style.display=="" || DateLayer.style.display=="block") && arguments[0]!=this.ClickObject && arguments[0]!=this.InputObject){
                DateLayer.style.display="none";
            }
        }
        catch(e){}
        }
    }
    
document.writeln('<iframe id="L_DateLayer" name="L_DateLayer" frameborder="0" scrolling="no" width="320" style="position:absolute;width:320px; height:190px;z-index:9997;display:none;"></iframe>');
var MyCalendar=new L_calendar();
MyCalendar.NewName="MyCalendar";

document.onclick=function(e)
{
	//alert("calendar");
    e = window.event || e;
    var srcElement = e.srcElement || e.target;
    MyCalendar.CloseLayer(srcElement);
    
    //国内城市
    if( document.getElementById("city_popup") )
    {
    	if( srcElement && srcElement.id && srcElement.id=='display_reset_link'){
    		return ;
    	}
    	
        if((objPopup.style.display=="" || objPopup.style.visibility=="visible")
         && srcElement!=kongj 
         && srcElement!=objPopup 
         && srcElement!=clicObj ){
            if( objPopup.style )objPopup.style.visibility="hidden";
        }
    }
    
    // 票城市选择窗口操作
    if( document.getElementById("fc_city_popup") )
    {
        if((fc_objPopup.style.display=="" || fc_objPopup.style.visibility=="visible") && srcElement!=fc_kongj && srcElement!=fc_objPopup && srcElement!=fc_clicObj){
            if( fc_objPopup.style )fc_objPopup.style.visibility="hidden";
        }
    }
    if( document.getElementById("fc_city_popup") )
    {
    //if(srcElement!=document.getElementById("fc_fromcity") && srcElement!=document.getElementById("fc_tocity")){
    	if(fc_objPopup.style && fc_objPopup.style.visibility=="hidden"){
    		try{
    			//visibleSelect();
    		}catch(e){
    		}
    	}
    }
}

